

FirstLua={};
local this=FirstLua;
local num=0;
local ParticleSystem = UnityEngine.ParticleSystem;
local GameObject = UnityEngine.GameObject;
local PrimitiveType = UnityEngine.PrimitiveType;
local Ray = UnityEngine.Ray;
local Input = UnityEngine.Input;
local Camera = UnityEngine.Camera;
local RaycastHit = UnityEngine.RaycastHit;
local Physics = UnityEngine.Physics;
local Text = UnityEngine.UI.Text;


this.Score=0;

--整个lua逻辑的入口
function FirstLua.OnInitOK()
    this.ScoreText = GameObject.Find("Text"):GetComponent(typeof(Text));
    
	coroutine.start(this.CreateMouse)

    coroutine.start(this.Update)
end


function this.CreateMouse()
	while(true)do
		coroutine.wait(1);
		
		local go=GameObject.CreatePrimitive(PrimitiveType.Cube);
		go.tag="Player";
		go.transform.position=Vector3(math.random(10,20),math.random(10,20),math.random(10,20));
	end
end


function this.Update()
	while(true) do
		coroutine.step();
		
        if(Input.GetMouseButtonDown(0))then	
            local ray = Camera.main:ScreenPointToRay(Input.mousePosition);
            local flag, hit = Physics.Raycast(ray, nil);
            if(flag)then
        	
                if(hit.collider.gameObject.tag=="Player")then

            	    GameObject.Destroy(hit.collider.gameObject);
            	    AddNum(num)
            	    
            	
                end
            end

        end
 		
	end
end
function AddNum(num)
	this.Score=this.Score+1;
	this.ScoreText.text="Score:"..this.Score;
	
end